package cn.ffcs.uec.outStaffAdjustPostApply.action;

import java.text.ParseException;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Messagebox;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.uec.common.manager.CustomFilesManager;
import cn.ffcs.uec.common.util.NodeVoUtil;
import cn.ffcs.uec.common.util.UecConstants;
import cn.ffcs.uec.common.vo.UecBdPsncl;
import cn.ffcs.uec.common.vo.UecWaPrmlv;
import cn.ffcs.uec.common.vo.UecWaSeclv;
import cn.ffcs.uec.organization.manager.UecOrgDeptManager;
import cn.ffcs.uec.outStaff.model.UecOutStaffInfo;
import cn.ffcs.uec.outStaffAdjustPostApply.action.bean.OutStaffAdjustPostApplyEditBean;
import cn.ffcs.uec.post.manager.UecPostManager;
import cn.ffcs.uec.post.model.UecPost;
import cn.ffcs.uec.recordsApproval.constant.ApprovalConstants;
import cn.ffcs.uec.recordsApproval.util.ApprovalUtil;
import cn.ffcs.uec.salary.manager.UecSalaryProjectManager;
import cn.ffcs.uec.salary.manager.UecWaCrtManager;
import cn.ffcs.uec.salary.model.UecSalaryProject;
import cn.ffcs.uec.salary.model.UecWaCrt;
import cn.ffcs.uec.staff.manager.UecPsnjobManager;
import cn.ffcs.uec.staff.model.UecPsndocWadoc;
import cn.ffcs.uec.staff.model.UecPsnjob;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.DateUtil;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PlatformUtil;
import cn.ffcs.uom.common.util.StrUtil;

@Controller
@Scope("prototype")
public class OutStaffAdjustPostApplyEditComposer extends BasePortletComposer {

	private static final long serialVersionUID = -3562782894231295110L;

	/**
	 * 定调资页面bean
	 */
	private OutStaffAdjustPostApplyEditBean bean = new OutStaffAdjustPostApplyEditBean();

	/**
	 * 操作类型
	 */
	private String opType;
	// /**
	// * 自定义档案
	// */
	// private CustomFiles customFiles;
	/**
	 * 薪资标准等级 == 岗位等级
	 */
	private UecWaPrmlv uecWaPrmlv;
	/**
	 * 薪资标准档别
	 */
	private UecWaSeclv uecWaSeclv;

	/**
	 * 外包人员基本信息
	 */
	private UecOutStaffInfo uecOutStaffInfo;
	/**
	 * 薪资标准
	 */
	private UecWaCrt uecWaCrt;
	/**
	 * 任职信息
	 */
	private UecPsnjob uecPsnjob;

	/**
	 * 人员类别
	 */
	private UecBdPsncl uecBdPsncl;
	/**
	 * 薪资变动情况
	 */
	private UecPsndocWadoc uecPsndocWadoc;
	/**
	 * 薪资变动情况
	 */
	private UecPsndocWadoc uecPsndocWadocHis;
	/**
	 * 薪资项目
	 */
	private UecSalaryProject uecSalaryProject;
	/**
	 * 岗位基本信息
	 */
	private UecPost uecPost;

	private String levelPost = "";

	/**
	 * 获取manager
	 */
	private UecWaCrtManager uecWaCrtManager = (UecWaCrtManager) ApplicationContextUtil
			.getBean("uecWaCrtManager");

	private UecPostManager uecPostManager = (UecPostManager) ApplicationContextUtil
			.getBean("uecPostManager");

	private UecSalaryProjectManager uecSalaryProjectManager = (UecSalaryProjectManager) ApplicationContextUtil
			.getBean("uecSalaryProjectManager");

	private UecPsnjobManager uecPsnjobManager = (UecPsnjobManager) ApplicationContextUtil
			.getBean("uecPsnjobManager");

	private UecOrgDeptManager uecOrgDeptManager = (UecOrgDeptManager) ApplicationContextUtil
			.getBean("uecOrgDeptManager");

	private CustomFilesManager customFilesManager = (CustomFilesManager) ApplicationContextUtil
			.getBean("customFilesManager");

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);

		this.bean.getUecWaCrtBandboxExt().addForward("onUecWaCrtEditSelected",
				comp, "onUecWaCrtEditSelectedResponse");
	}

	/**
	 * 初始化
	 * 
	 * @throws ParseException
	 */
	public void onCreate$outStaffAdjustPostApplyEditWindow()
			throws ParseException {
		this.bindBean();
		bean.getApplyCriterionvalue().setDisabled(true);
		bean.getApplyNmoney().setDisabled(true);
	}

	/**
	 * 选择是否谈判工资事件 谈判工资=否，薪资标准、标准金额 显示 谈判工资=是，薪资标准、标准金额 不显示
	 */
	public void onCheck$negotiationWage() {
		int index = bean.getNegotiationWage().getSelectedIndex();
		if (0 == index) {
			bean.getPkWaCrtLabel().setVisible(true);
			bean.getUecWaCrtBandboxExt().setVisible(true);
			bean.getApplyCriterionvalueLabel().setVisible(true);
			bean.getApplyCriterionvalue().setVisible(true);
			bean.getApplyCriterionvalue().setDisabled(true);
			bean.getApplyNmoney().setDisabled(true);
			// 切换时清空相应的Textbox
			bean.getUecWaCrtBandboxExt().setValue(null);
			bean.getApplyNmoney().setValue(null);
			bean.getApplyCriterionvalue().setValue(null);
		} else {
			bean.getPkWaCrtLabel().setVisible(false);
			bean.getUecWaCrtBandboxExt().setVisible(false);
			bean.getApplyCriterionvalueLabel().setVisible(false);
			bean.getApplyCriterionvalue().setVisible(false);
			bean.getApplyNmoney().setDisabled(false);
			bean.getApplyNmoney().setValue(null);
			// 切换时清空相应的Textbox
			bean.getUecWaCrtBandboxExt().setValue(null);
			bean.getApplyNmoney().setValue(null);
			bean.getApplyCriterionvalue().setValue(null);
		}
	}

	/**
	 * 监听UecWaCrtBandboxExt抛出的获取选中的薪资标准
	 * 
	 * @param event
	 */
	public void onUecWaCrtEditSelectedResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			uecWaCrt = (UecWaCrt) event.getOrigin().getData();
			if (null != uecWaCrt) {
				// 判断填入的岗位等级，与原始的岗位等级是否一样
				// if (uecWaCrt.getPostGrade().equals(levelPost)) {
				// 动态设置--标准金额、金额
				if (!StrUtil.isNullOrEmpty(uecWaCrt.getWaCrtMoney())) {
					// 设置标准金额
					bean.getApplyCriterionvalue().setValue(
							uecWaCrt.getWaCrtMoney());
					// 设置表准金额
					bean.getApplyNmoney().setValue(uecWaCrt.getWaCrtMoney());
				}
				// 设置薪资标准级别
				// 薪资等级==岗位等级
				uecWaPrmlv = new UecWaPrmlv();
				uecWaPrmlv.setPkWaGrd(uecPsndocWadoc.getPkWaGrd());
				uecWaPrmlv.setLevelName(uecWaCrt.getPostGrade());
				uecWaPrmlv = customFilesManager
						.findObjectByUecWaPrmlv(uecWaPrmlv);
				uecPsndocWadoc.setPkWaPrmlv(uecWaPrmlv.getPkWaPrmlv());

				// 薪资档别
				uecWaSeclv = new UecWaSeclv();
				uecWaSeclv.setPkWaGrd(uecPsndocWadoc.getPkWaGrd());
				uecWaSeclv.setLevelName(uecWaCrt.getSalaryGrade());
				uecWaSeclv = customFilesManager
						.findObjectByUecWaSeclv(uecWaSeclv);
				uecPsndocWadoc.setPkWaSeclv(uecWaSeclv.getPkWaSeclv());
				// } else {
				// ZkUtil.showInformation("岗位等级只能填：" + levelPost, "温馨提示");
				// bean.getUecWaCrtBandboxExt().setValue(null);
				// }
			}
		}
	}

	/**
	 * bindBean
	 * 
	 * @throws ParseException
	 */
	public void bindBean() throws ParseException {
		opType = (String) arg.get("opType");
		if ("add".equals(opType)) {
			// 设置弹出页面的标题
			bean.getOutStaffAdjustPostApplyEditWindow().setTitle("外包员工调薪新增");
			// 初始化-申请薪资不可见
			bean.getGroupBox3().setVisible(false);
			// 初始化-申请薪资不可见
			// bean.getGroupBox4().setVisible(false);
			ListboxUtils.rendererForEdit(bean.getPkChangecause(),
					NodeVoUtil.getDictionaries(UecConstants.WAGE_CHANGE_CAUSE));
			// 获取外包人员基本信息
			uecOutStaffInfo = (UecOutStaffInfo) arg.get("uecOutStaffInfo");
			if (uecOutStaffInfo != null) {
				// 清楚变量
				clearVariable();
				// 设置--人员编码、姓名
				bean.getPsnCode().setValue(uecOutStaffInfo.getPsnCode());
				bean.getPsnName().setValue(uecOutStaffInfo.getPsnName());
				// 获取--uecPsnjob
				if (!StrUtil.isNullOrEmpty(uecOutStaffInfo.getOutStaffId())) {
					uecPsnjob = new UecPsnjob();
					uecPsnjob.setStaffId(uecOutStaffInfo.getOutStaffId());
					uecPsnjob
							.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);

					uecPsnjob = uecPsnjobManager.findNewUecPsnjob(uecPsnjob);
					if (!StrUtil.isNullOrEmpty(uecPsnjob)) {
						// 部门
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getPkDept())) {
							bean.getDeptName()
									.setValue(
											uecOrgDeptManager
													.getUecOrgDeptNameByPkDept(uecPsnjob
															.getPkDept()));
						}
						// 基准岗位
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getJobglbdef24())) {
							uecPost = new UecPost();
							uecPost.setPkPost(uecPsnjob.getJobglbdef24());
							uecPost = uecPostManager.queryUecPost(uecPost);
							if (null != uecPost) {
								if (!StrUtil.isNullOrEmpty(uecPost
										.getPostname())) {
									bean.getJobName().setValue(
											uecPost.getPostname());
								}
							}
						}
						// 岗位
						/*if (!StrUtil.isNullOrEmpty(uecPsnjob.getOutJobName())) {
							bean.getJobName().setValue(
									uecPsnjob.getOutJobName());
						}*/
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getPkPostName())) {
							bean.getJobName().setValue(
									uecPsnjob.getPkPostName());
						}
						// 人员类别
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getPkPsncl())) {
							uecBdPsncl = new UecBdPsncl();
							uecBdPsncl.setPkPsncl(uecPsnjob.getPkPsncl());
							uecBdPsncl = customFilesManager
									.findUecUecBdPsnclByUecBdPsncl(uecBdPsncl);
							if (!StrUtil.isNullOrEmpty(uecBdPsncl)) {
								if (!StrUtil
										.isNullOrEmpty(uecBdPsncl.getName())) {
									bean.getPkPsncl().setValue(
											uecBdPsncl.getName());
								}
							}
						}
						// 职务
						if (!StrUtil.isNullOrEmpty(uecPsnjob.getJobglbdef4())) {
							bean.getJobGlbdef4().setValue(
									uecPsnjob.getJobglbdef4());
						}
						// 岗位序列：此处岗位序列表--LDAPM_MPW_OM_POSTSERIES中只有两条记录，古此处暂时这样处理
						if ("1001A1100000000006R2".equals(uecPsnjob
								.getPkPostseries())) {
							bean.getPkPostSeries().setValue("管理序列");
						} else if ("1001A1100000000006R3".equals(uecPsnjob
								.getPkPostseries())) {
							bean.getPkPostSeries().setValue("专业序列");
						} else {
							bean.getPkPostSeries().setValue(null);
						}
					}
				}
				// 获取薪资变动情况信息
				uecPsndocWadocHis = (UecPsndocWadoc) arg.get("uecPsndocWadoc");
				// 新对象
				uecPsndocWadoc = new UecPsndocWadoc();
				uecPsndocWadoc = (UecPsndocWadoc) uecPsndocWadocHis.clone();
				if (uecPsndocWadocHis != null) {
					// 申请薪资可见
					bean.getGroupBox3().setVisible(true);
					// 申请薪资可见
					// bean.getGroupBox4().setVisible(true);

					if (!StrUtil
							.isNullOrEmpty(uecPsndocWadocHis.getBegindate())) {
						bean.getBeginDate().setValue(
								uecPsndocWadocHis.getBegindate());
					}
					// 薪资项目
					if (!StrUtil.isNullOrEmpty(uecPsndocWadocHis.getPkWaItem())) {
						uecSalaryProject = new UecSalaryProject();
						uecSalaryProject.setPkWaItem(uecPsndocWadocHis
								.getPkWaItem());
						uecSalaryProject = uecSalaryProjectManager
								.findObjectByUecSalaryProject(uecSalaryProject);
						if (null != uecSalaryProject) {
							if (!StrUtil.isNullOrEmpty(uecSalaryProject
									.getName())) {
								bean.getPkWaItem().setValue(
										uecSalaryProject.getName());
							}
						}
					}
					// 原薪资 是否谈判薪资
					if (!StrUtil.isNullOrEmpty(uecPsndocWadocHis
							.getNegotiationWage())) {
						if ("N".equals(uecPsndocWadocHis.getNegotiationWage())) {
							bean.getNegotiationWageHis().setValue("否");
						} else {
							bean.getNegotiationWageHis().setValue("是");
						}
					}
					// 薪资标准
					if (!StrUtil
							.isNullOrEmpty(uecPsndocWadocHis.getPkWaSeclv())
							&& !StrUtil.isNullOrEmpty(uecPsndocWadocHis
									.getPkWaPrmlv())) {
						// 薪资级别==岗位等级
						uecWaPrmlv = new UecWaPrmlv();
						uecWaPrmlv.setPkWaPrmlv(uecPsndocWadocHis
								.getPkWaPrmlv());
						uecWaPrmlv = customFilesManager
								.findObjectByUecWaPrmlv(uecWaPrmlv);
						// 薪资档别
						uecWaSeclv = new UecWaSeclv();
						uecWaSeclv.setPkWaSeclv(uecPsndocWadocHis
								.getPkWaSeclv());
						uecWaSeclv = customFilesManager
								.findObjectByUecWaSeclv(uecWaSeclv);
						if (null != uecWaPrmlv && null != uecWaSeclv) {

							if (!StrUtil.isNullOrEmpty(uecWaPrmlv
									.getLevelName())
									&& !StrUtil.isNullOrEmpty(uecWaSeclv
											.getLevelName())) {
								// 设置薪资标准4/A
								uecWaCrt = new UecWaCrt();
								uecWaCrt.setPostGrade(uecWaPrmlv.getLevelName()); // 岗级
								// 获取岗位等级
								levelPost = uecWaPrmlv.getLevelName();
								bean.getPostLevel().setValue(levelPost);
								// 薪资档别
								uecWaCrt.setSalaryGrade(uecWaSeclv
										.getLevelName());
								uecWaCrt = uecWaCrtManager
										.findObjectByUecWaCrt(uecWaCrt);

								if (uecWaCrt != null) {
									if (!StrUtil.isNullOrEmpty(uecWaCrt
											.getWaCrtName())) {
										bean.getPkWaCrt().setValue(
												uecWaCrt.getWaCrtName());
									}
								}
							}
						}
					}
					// 标准金额
					if (!StrUtil.isNullOrEmpty(uecPsndocWadocHis
							.getCriterionvalue())) {
						bean.getCriterionvalue().setValue(
								String.valueOf(uecPsndocWadocHis
										.getCriterionvalue()));
					}
					// 金额
					if (!StrUtil.isNullOrEmpty(uecPsndocWadocHis.getNmoney())) {
						bean.getNmoney().setValue(
								String.valueOf(uecPsndocWadocHis.getNmoney()));
					}
					// 执行日期
					if (!StrUtil
							.isNullOrEmpty(uecPsndocWadocHis.getBegindate())) {
						bean.getBeginDate().setValue(
								uecPsndocWadocHis.getBegindate());
					}
					// 薪资标准类别
					if (!StrUtil.isNullOrEmpty(uecPsndocWadocHis.getPkWaGrd())) {
						if ("1001A1100000000B2DPQ".equals(uecPsndocWadocHis
								.getPkWaGrd())) {
							bean.getPkWaGrd().setValue("集团薪资标准（新岗新体系）");
						} else if ("1001A1100000000A7FIO"
								.equals(uecPsndocWadocHis.getPkWaGrd())) {
							bean.getPkWaGrd().setValue("集团薪资标准（旧岗新体系）");
						} else if ("1001A1100000000A83WH"
								.equals(uecPsndocWadocHis.getPkWaGrd())) {
							bean.getPkWaGrd().setValue("内蒙古薪资标准（旧岗新体系）");
						} else if ("1001A1100000000TRON2"
								.equals(uecPsndocWadocHis.getPkWaGrd())) {
							bean.getPkWaGrd().setValue("薪资表（旧体系）");
						}
					}
					// 备注
					bean.getVnotehis().setValue(uecPsndocWadocHis.getVnote());
					// 依据文件
					bean.getVbasefileHis().setValue(
							uecPsndocWadocHis.getVbasefile());
					// 变动原因
					String changecause = customFilesManager
							.findCustomFilesByPkdefdoc(uecPsndocWadoc
									.getPkChangecause());
					bean.getPkChangecauseHis().setValue(changecause);
				}
			}
		}
	}

	/**
	 * @throws Exception
	 * 
	 */
	public void onSave() throws Exception {
		if (null == uecOutStaffInfo || null == uecOutStaffInfo.getOutStaffId()) {
			ZkUtil.showError("未获取人员！", "错误提示");
			return;
		}
		String msg = this.checkUacStaffData();
		if (uecOutStaffInfo == null) {
			ZkUtil.showError("外包人员基本信息为空", "错误提示");
			return;
		} else if (uecPsndocWadocHis == null) {
			ZkUtil.showError("外包人员原薪资记录不存在，请先进行入职操作！", "错误提示");
			return;
		} else if (null != msg) {
			Messagebox.show(msg);
			return;
		}
		if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
			ZkUtil.showError("当前登录用户不存在!", "错误提示");
			return;
		}
		String currentName = PlatformUtil.getCurrentUser().getScreenName();
		
		/**
		 * 生效日期，为新数据的薪资开始日期，为旧数据的薪资结束日期
		 * 执行日期：为新薪资的调整日期
		 */
		String effectDate = DateUtil.dateToStr(bean.getEffectDate().getValue());
		String applyDate = DateUtil.dateToStr(bean.getApplyBeginDate().getValue());
		
		// 日/月表按钮
		int index = bean.getNegotiationWage().getSelectedIndex();
		// index == 0 表示谈判工资为否
		if (index == 0) {
			// 获取是否谈判工资
			uecPsndocWadoc.setNegotiationWage("N");
			// 获取标准金额
			uecPsndocWadoc.setCriterionvalue(Double.parseDouble(bean
					.getApplyNmoney().getValue()));
			// 获取金额
			uecPsndocWadoc.setNmoney(Double.parseDouble(bean.getApplyNmoney()
					.getValue()));
		} else {
			/**
			 * 否则是谈判工资 如果是谈判工资，那么就不存在标准薪资，相关数据全部清空
			 */
			// 获取是否谈判工资
			uecPsndocWadoc.setNegotiationWage("Y");
			// 获取金额
			uecPsndocWadoc.setNmoney(Double.parseDouble(bean.getApplyNmoney()
					.getValue()));
			// 标准金额
			uecPsndocWadoc.setCriterionvalue(null);
		}
		// 薪资开始日期
		uecPsndocWadoc.setBegindate(effectDate);
		// 薪资调整日期
		uecPsndocWadoc.setChangedate(applyDate);
		// 获取变动原因
		uecPsndocWadoc.setPkChangecause(String.valueOf(bean.getPkChangecause()
				.getSelectedItem().getValue()));
		// 依据文件
		uecPsndocWadoc.setVbasefile(bean.getVbasefile().getValue());
		// 获取备注
		uecPsndocWadoc.setVnote(bean.getVnote().getValue());
		// 是否最新记录
		uecPsndocWadoc.setLastflag("Y");
		// 创建人
		uecPsndocWadoc.setCreator(currentName);
		// 创建时间
		uecPsndocWadoc.setCreationtime(DateUtil.getCurrenDate());
		/**
		 * 历史数据的结束日期，为新数据的执行日期
		 */
		// 历史数据结束日期，为生效日期
		uecPsndocWadocHis.setEnddate(effectDate);
		// 是否最新标识
		uecPsndocWadocHis.setLastflag("N");
		// 修改人
		uecPsndocWadocHis.setModifier(currentName);
		// 修改时间
		uecPsndocWadocHis.setModifiedtime(DateUtil.getCurrenDate());

		/**
		 * uecPsndocWadocHis 历史对象 需要 更新, uecPsndocWadoc 新对象 需要新增
		 */
		// 发起流程
		if (ApprovalUtil.getActivityFlag()) {
			// 判断该人员是否在审状态，如果是在审状态不允许再次发起此流程
			boolean isOnApproval = ApprovalUtil.isOnApproval(
					ApprovalConstants.OUT_STAFF_ADJUST_POST_PROC_DEF_ID,
					uecOutStaffInfo.getOutStaffId());
			if (isOnApproval) {
				ZkUtil.showError("在审状态不允许发起！", "错误提示");
				return;
			}

			/**
			 * 数据入库 修改 薪资变动情况表 uec_psndoc_wadoc 一条记录,增加薪资变动情况表 uec_psndoc_wadoc
			 * 一条记录
			 */
			Long outStaffIdHis = uecOutStaffInfo.getOutStaffId();
			Long outStaffId = outStaffIdHis;

			Long wadocIdHis = uecPsndocWadocHis.getWadocId();
			uecPsndocWadocHis.addStatusCdIS3();
			Long wadocIdModify = uecPsndocWadocHis.getWadocId();

			uecPsndocWadoc.setStaffId(outStaffId);
			uecPsndocWadoc.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);
			uecPsndocWadoc.addStatusCdIS3();
			Long wadocIdAdd = uecPsndocWadoc.getWadocId();

			String formTheme = "盟市外包人员定调资申请流程";

			String startFlowJson = "{" + "formTheme: '" + formTheme + "',"
					+ " formContent: '申请人员:" + uecOutStaffInfo.getPsnName()
					+ "'," + " procDefId: '"
					+ ApprovalConstants.OUT_STAFF_ADJUST_POST_PROC_DEF_ID
					+ "'," + " urgent: '1'," + " atiActCategoryId: '"
					+ ApprovalConstants.ADJUST_POST_CATEGORY_ID + "',"
					+ " procDefKey: '" + ApprovalUtil.OUT_STAFF_ADJUST_POST
					+ "'," + " formSender: '" + currentName + "',"
					+ " primaryId: '{" + "uec_out_staff_info_his:"
					+ outStaffIdHis + ",uec_out_staff_info:" + outStaffId
					+ ",uec_psndoc_wadoc_his:" + wadocIdHis
					+ ",uec_psndoc_wadoc_modi:" + wadocIdModify
					+ ",uec_psndoc_wadoc_add:" + wadocIdAdd + "'}";

			String procInstId = null;
			try {
				procInstId = ApprovalUtil.startApproval(startFlowJson);
			} catch (Exception e) {
				// 流程发起失败 插入的数据 变为失效状态
				uecPsndocWadoc.removeOnly();
				onCancel();
				ZkUtil.showError("流程发起失败！", "错误提示");
				e.printStackTrace();
			}

			if (StrUtil.isNullOrEmpty(procInstId)) {
				uecPsndocWadoc.removeOnly();
				onCancel();
				ZkUtil.showError("流程发起失败！", "错误提示");
				return;
			}
			// 第一审批人如果是发起人直接到人力审批环节
			ApprovalUtil.isCurrentAssignNames(procInstId);

			ApprovalUtil.showNextAssignee(procInstId, formTheme);

			Events.postEvent("onOK", this.self, uecOutStaffInfo);
			// 关闭窗口
			this.onCancel();
		} else {
			// 更新历史数据数据
			uecPsndocWadocHis.updateOnly();
			// 新增新的数据
			uecPsndocWadoc.addOnly();
			// 抛出事件
			Events.postEvent("onOK", this.self, uecOutStaffInfo);
			// 流程发起提示
			ZkUtil.showInformation("数据保存成功", "温馨提示");
			// 关闭窗口
			this.onCancel();
		}
	}

	/**
	 * 取消并关闭窗口
	 */
	public void onCancel() {
		// 关闭窗口
		this.bean.getOutStaffAdjustPostApplyEditWindow().onClose();
	}

	/**
	 * 检测填入的参数是否为空
	 */
	public String checkUacStaffData() {
		if (StrUtil.isNullOrEmpty(bean.getEffectDate().getValue())) {
			return "请选择生效日期";
		}else if (StrUtil.isNullOrEmpty(bean.getApplyBeginDate().getValue())) {
			return "请选择执行日期";
		}
		// 是否谈判工资
		if (0 == bean.getNegotiationWage().getSelectedIndex()) {
			if (StrUtil.isNullOrEmpty(bean.getUecWaCrtBandboxExt().getValue())) {
				return "请选择薪资标准";
			}
		}
		if (1 == bean.getNegotiationWage().getSelectedIndex()) {
			if (StrUtil.isNullOrEmpty(bean.getApplyNmoney().getValue())) {
				return "请填写金额";
			} else if (StrUtil.checkBlank(bean.getNmoney().getValue())) {
				return "金额中有空格";
			}
		}
		if (StrUtil.isNullOrEmpty(bean.getPkChangecause().getSelectedItem()
				.getValue())) {
			return "请选择变动原因";
		}
		return null;
	}

	/**
	 * 清除变量
	 */
	public void clearVariable() {
		uecWaPrmlv = null;
		uecWaSeclv = null;
		uecWaCrt = null;
		uecPsnjob = null;
		uecPsnjob = null;
		uecBdPsncl = null;
		uecPsndocWadoc = null;
		uecSalaryProject = null;
		uecPost = null;
		bean.getPkWaCrt().setValue(null);
		bean.getCriterionvalue().setValue(null);
		bean.getNmoney().setValue(null);
	}
}
